package actions;

import java.sql.SQLException;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.StudentModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
//import forms.StudentForm;
import model.AdminModel;

public class AdminGetDisciplinesAction extends Action {

	private static final boolean DEBUG = true;

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws DbException {
		
		String path = mapping.getPath();
		
		if (DEBUG) {
			System.err.println("AdminGetDisciplinesAction: " + path);
		}
		
		// Retrieve all disciplines
		RowSet disciplineSet = AdminModel.getAllDisciplines();
		Vector<String> disciplineVector = new Vector<String>();
		// Store all the disciplines into a vector
		try {
		while(disciplineSet.next())
		{
			disciplineVector.add(disciplineSet.getString(1));
			
		} } catch (SQLException e) {
			throw new DbException(e);
		}
		
		// Store the Vector in the request scope
		request.setAttribute("disciplineVector", disciplineVector);
			
		Vector<String> disciplineValues = AdminModel.getDisciplineValues();
		
		request.setAttribute("disciplineValues", disciplineValues);
		
		
		return mapping.findForward("success");
	}
}